|
|
|
|
|
|
|
Solution 3
Poly Want a Cracker? |
|
|
|
|
|
|
|
|
The API declaration is an obvious place. The hdc parameter is a handle, a| 32-bit value that identifies an object. In this case, it is a handle to a device context, an object that acts as an interface between a physical device (such as a window on the screen or a printed page) and the drawing subsystem. Since you wish to pass the value of the handle as a parameter, you must specify the ByVal operator for the parameter. The same thing applies to the nCount parameter. The correct declaration is as follows: |
|
|
|
|
|
|
|
|
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, _
lpPoint As POINTAPI, ByVal nCount As Long) As Long |
|
|
|
|
|
|
|
|
This fix leads to (drum roll, please) . . . another blank screen. |
|
|
|
|
|
|
|
|
The next step is to trace through and look at the result of the Polygon function. This will be easier if you change the Polygon call to use the function format as shown here: |
|
|
|
|
|
|
|
|
Result = Polygon(hWnd, points(0), UBound(points) + 1) |
|
|
|
|
|
|
|
|
The result is 0, which indicates that the function failed. If you examine the last error value by displaying the value of the Err.LastDllError property, you'll see the result is 6. You can use the FormatMessage function introduced in Puzzle 2 or look up the ERROR_ constants in the api32.txt or winerror.h file (on the CD that comes with this book) to find the matching error value: |
|
|
|
|
|
|
|
|
' The handle is invalid.
Public Const ERROR_INVALID_HANDLE = 6& |
|
|
|
|
|
|
|
|
Take a close look at the first parameter, the handle. The function documentation defines this as a handle to a device context. But the code is using a handle to a window. Windows and device contexts are two very different things. |
|
|
|
|
|
|
|
|
Call Polygon(hWnd, points(0), UBound(points) + 1) |
|
|
|
|
|